﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace JScriptSuite.QA.Lib.System
{
    class ArrayTests
    {
        internal static JResultItem AllTests()
        {
            return JResultItem.CreateInstance("ArrayTests")
                .Push(EnumerableTests(),
                    ListTests(),
                    TypedListTests()
                    );
        }

        static JResultItem EnumerableTests()
        {
            JResultItem resultItem = JResultItem.CreateInstance("EnumerableTests");
            int[] ar = new int[] { 1, 3, 2, 5, 4 };
            object o = ar;
            IEnumerable enumerable = o as IEnumerable;
            resultItem.Push(o is IEnumerable, enumerable != null);
            int index = 0;
            foreach (int elem in enumerable)
            {
                resultItem.Push(ar[index++] == elem);
            }

            return resultItem;
        }

        static JResultItem ListTests()
        {
            JResultItem resultItem = JResultItem.CreateInstance("ListTests");
            int[] ar = new int[] { 1, 3, 2, 5, 4 };
            object o = ar;
            IList list = o as IList;
            resultItem.Push(o is IList, list != null);
            for (int i = 0; i < list.Count; i++)
            {
                resultItem.Push(ar[i] == (int)list[i]);
            }

            return resultItem;
        }

        static JResultItem TypedListTests()
        {
            JResultItem resultItem = JResultItem.CreateInstance("TypedListTests");
            int[] ar = new int[] { 1, 3, 2, 5, 4 };
            object o = ar;
            IList<int> list = o as IList<int>;
            resultItem.Push(o is IList, list != null);
            for (int i = 0; i < list.Count; i++)
            {
                resultItem.Push(ar[i] == list[i]);
            }


            return resultItem;
        }

    }
}
